package com.lhq.business.repo;

import com.lhq.business.entity.NovelBook;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.mongodb.repository.MongoRepository;

import java.util.List;

public interface NovelBookRepository extends MongoRepository<NovelBook, String> {
    /**
     * 查询小说章节
     * @param novelBook
     * @return: java.util.List<com.lhq.business.entity.NovelBook>
     * @author lhq
     * @date: 2024/7/26 10:11
     */
    public default List<NovelBook> findAll(NovelBook novelBook){
        ExampleMatcher matcher = ExampleMatcher.matching()
                .withStringMatcher(ExampleMatcher.StringMatcher.DEFAULT)
                .withIgnoreNullValues()
                .withIgnorePaths("_class");
        Example<NovelBook> example = Example.of(novelBook, matcher);
        return this.findAll(example);
    }

    /**
     * 查询小说章节
     * @param novelBook
     * @return: java.util.List<com.lhq.business.entity.NovelBook>
     * @author lhq
     * @date: 2024/7/26 10:11
     */
    public default Page<NovelBook> findAll(NovelBook novelBook, int page, int size){
        ExampleMatcher matcher = ExampleMatcher.matching()
                .withStringMatcher(ExampleMatcher.StringMatcher.DEFAULT)
                .withIgnoreNullValues()
                .withIgnorePaths("_class");
        Example<NovelBook> example = Example.of(novelBook, matcher);
        return this.findAll(example, PageRequest.of(page, size));
    }


}